<%@page language="java" contentType="text/html; charset=utf-8"%>
<%@include file="/tagDeclare.jsp"%>
<%@include file="/headDeclare.jsp"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="<%=basePath%>js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=basePath%>js/ztree/jquery.ztree.all-3.5.js"></script>
<link rel="stylesheet" href="<%=basePath%>css/ztree/zTree.css" type="text/css">
<link rel="stylesheet" href="<%=basePath%>css/ztree/zTreeStyle/zTreeStyle.css" type="text/css">
<script type="text/javascript">
	var dialog = frameElement.dialog; //调用页面的dialog对象(ligerui对象)
	var rightSetting = {
		check : {
			enable : true
		},
		view : {
			dblClickExpand : dblClickExpand
		},
		data : {
			simpleData : {
				enable : true
			}
		}
	};
	function dblClickExpand(treeId, treeNode) {
		return treeNode.level > 0;
	}
	var rightNodes = ${rightJson};
	
	$(function() {
		$.fn.zTree.init($("#rightTree"), rightSetting, rightNodes);
	});
	function checkSubmit() {
		var selectStr = "";
		var treeObj = $.fn.zTree.getZTreeObj("rightTree");
		var nodes = treeObj.getCheckedNodes(true);
		if (nodes.length == 0) {
			$.ligerDialog.alert("请选择权限");
			return false;
		}

		for (var j = 0; j < nodes.length; j++) {
			selectStr += "," + nodes[j].id;
		}
		if (!isEmpty(selectStr)) {
			selectStr = selectStr.substring(1);
		}
		$("#select").val(selectStr);
		var params = $("#configForm").serialize();
		var url = "${basePath}roleright/update.do?" + params;
		$.post(url, function(result) {
			var res = eval('(' + result + ')');
			if (res.code == 0) {
				$.ligerDialog.error(res.message);
				return false;
			} else {
				$.ligerDialog.alert("配置成功");
				dialog.close();
			}
		});
	}
</script>
</head>
<body>
	<form action="${basePath}roleright/update.do" id="configForm" name="configForm" method="post">
		<input type="hidden" name="select" value="111" id="select" />
		<input type="hidden" name="id" value="${role.id }" />
		<div class="dialogTop">
			<table width="100%" border="0" align="center" cellspacing="10" cellpadding="0">
				<tr>
					<td>角色名称 : ${role.roleName}</td>
				</tr>
				<tr>
					<td>
						<div id="rightTree" class="ztree" sstyle="width:480px;border:1px solid #ccc;background-color: rgb(250, 250, 250);"></div>
					</td>
				</tr>
			</table>
		</div>
		<div class="dialogBottom">
			<div class="btns">
				<input type="button" value="配置" class="ldBtnGreen" onclick="checkSubmit();" />
				<input type="button" value="关闭" class="ldBtnGray" onclick="dialog.close()" />
			</div>
		</div>
	</form>
</body>
</html>